# ==== Replication File for "Hypercompetitiveness and Loser's Consent" ====
#
#
#
#
#
# Environment and Packages ----
#
rm(list = ls())
#
pacman::p_load(readxl, tidyverse, lavaan, psych, anesrake, survey, haven, ltm)
#
#
#
#
#
# Dataset
#
Qualtrics2022 <- read_excel("Qualtrics_2022.xlsx")
Qualtrics2022[] <- lapply(Qualtrics2022, as.numeric)
#
#
#
#
#
# Preparing Data ----
#
# This section recodes all variables that will be used in regressions for
# the article's results, including for weighting purposes.
#
#
# Hypercompetitiveness
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(fight = ifelse(newcomp2 == 1, 1, 
                        ifelse(newcomp2 == 2, 0, NA))) %>% 
  mutate(playtowin = ifelse(newcomp11 == 1, 1, 
                            ifelse(newcomp11 == 2, 0, NA))) %>% 
  mutate(fighters = ifelse(newcomp4 == 1, 0, 
                           ifelse(newcomp4 == 2, 1, NA))) %>% 
  mutate(ruthless = ifelse(newcomp8 == 1, 0, 
                           ifelse(newcomp8 == 2, 1, NA))) %>% 
  mutate(hypercompetitive = (fight + playtowin + fighters + ruthless)/4)
#
#
# January 6 Descriptors
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(acceptable = ifelse(Qualtrics2022$`Q382#1_1` == 1, 1, 0)) %>%
  mutate(unacceptable = ifelse(Qualtrics2022$`Q382#1_1` == 2, 1, 0)) %>%
  mutate(patriotic = ifelse(Qualtrics2022$`Q382#4_1` == 1, 1, 0)) %>%
  mutate(unpatriotic = ifelse(Qualtrics2022$`Q382#4_1` == 2, 1, 0)) %>%
  mutate(justified = ifelse(Qualtrics2022$`Q382#5_1` == 1, 1, 0)) %>%
  mutate(unjustified = ifelse(Qualtrics2022$`Q382#5_1` == 2, 1, 0)) %>%
  mutate(legitdiscourse = ifelse(Qualtrics2022$`Q382#2_1` == 2, 1, 0)) %>%
  mutate(violent = ifelse(Qualtrics2022$`Q382#2_1` == 1, 1, 0)) %>%
  mutate(unplanned = ifelse(Qualtrics2022$`Q382#3_1` == 2, 1, 0)) %>%
  mutate(planned = ifelse(Qualtrics2022$`Q382#3_1` == 1, 1, 0))
#
Qualtrics2022$acceptable <- replace_na(Qualtrics2022$acceptable, 0)
Qualtrics2022$unacceptable <- replace_na(Qualtrics2022$unacceptable, 0)
Qualtrics2022$patriotic <- replace_na(Qualtrics2022$patriotic, 0)
Qualtrics2022$unpatriotic <- replace_na(Qualtrics2022$unpatriotic, 0)
Qualtrics2022$justified <- replace_na(Qualtrics2022$justified, 0)
Qualtrics2022$unjustified <- replace_na(Qualtrics2022$unjustified, 0)
Qualtrics2022$legitdiscourse <- replace_na(Qualtrics2022$legitdiscourse, 0)
Qualtrics2022$violent <- replace_na(Qualtrics2022$violent, 0)
Qualtrics2022$unplanned <- replace_na(Qualtrics2022$unplanned, 0)
Qualtrics2022$planned <- replace_na(Qualtrics2022$planned, 0)
#
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(jan6_pos = acceptable + patriotic + justified + legitdiscourse + unplanned) %>%
  mutate(jan6_neg = unacceptable + unpatriotic + unjustified + violent + planned) %>%
  mutate(jan6ok_prop = jan6_pos/(jan6_pos + jan6_neg))
#
#
# Race
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(race_cat = ifelse(race == 1, "white", 
                           ifelse(race == 2, "black", 
                                  ifelse(race == 3, "hispanic", 
                                         ifelse(race == 4, "asian", 0))))) %>%
  mutate(white = ifelse(race == 1, 1, 0)) %>% 
  mutate(black = ifelse(race == 2, 1, 0)) %>% 
  mutate(hispanic = ifelse(race == 3, 1, 0)) %>% 
  mutate(asian = ifelse(race == 4, 1, 0))
Qualtrics2022$race_cat <- factor(Qualtrics2022$race_cat, levels = c("white", "black", "hispanic", "asian"))
#
#
# Age
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(age_recoded = ifelse(age == 2, 1, 
                              ifelse(age == 3, 2, 
                                     ifelse(age == 4, 3, 
                                            ifelse(age == 5, 4, 
                                                   ifelse(age == 6, 5, 
                                                          ifelse(age == 7, 6, 
                                                                 ifelse(age == 8, 7, 
                                                                        ifelse(age == 9, 7, NA))))))))) %>%
  mutate(age = (age_recoded - 1)/6) 

Qualtrics2022 <- Qualtrics2022 %>%
  mutate("18-24" = ifelse(age_recoded == 1, 1, 0)) %>%
  mutate("25-34" = ifelse(age_recoded == 2, 1, 0)) %>%
  mutate("35-44" = ifelse(age_recoded == 3, 1, 0)) %>%
  mutate("45-54" = ifelse(age_recoded == 4, 1, 0)) %>%
  mutate("55-64" = ifelse(age_recoded == 5, 1, 0)) %>%
  mutate("65-74" = ifelse(age_recoded == 6, 1, 0)) %>%
  mutate("75+" = ifelse(age_recoded == 7, 1, 0)) %>%
  mutate(age_cat = ifelse(age_recoded == 1, "18-24", 
                          ifelse(age_recoded == 2, "25-34", 
                                 ifelse(age_recoded == 3, "35-44", 
                                        ifelse(age_recoded == 4, "45-54", 
                                               ifelse(age_recoded == 5, "55-64",
                                                      ifelse(age_recoded == 6, "65-74",
                                                             ifelse(age_recoded == 7, "75+", NA))))))))
#
#
# Education
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(edu_cat = ifelse(edu == 1 | edu == 2, "hs_or_less", 
                          ifelse(edu == 3 | edu == 4, "some_college", 
                                 ifelse(edu == 5, "college", 
                                        ifelse(edu == 6 | edu == 7 | edu == 8, "grad_school", NA))))) %>% 
  mutate(hs_or_less = ifelse(edu == 1 | edu == 2, 1, 0)) %>% 
  mutate(some_college = ifelse(edu == 3 | edu == 4, 1, 0)) %>% 
  mutate(college = ifelse(edu == 5, 1, 0)) %>% 
  mutate(grad_school = ifelse(edu == 6 | edu == 7 | edu == 8, 1, 0))
Qualtrics2022$edu_cat <- factor(Qualtrics2022$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
# 
# Female
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(female = ifelse(gender == 2, 1, 0))
#
#
# Party ID
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(pid7 = ifelse(pid == 1 & dpid == 1, 1, 
                       ifelse(pid == 1 & dpid == 2, 2, 
                              ifelse(pid == 3 & lean == 2, 3, 
                                     ifelse(pid == 3 & lean == 3, 4, 
                                            ifelse(pid == 3 & lean == 1, 5, 
                                                   ifelse(pid == 2 & rpid == 2, 6, 
                                                          ifelse(pid == 2 & rpid == 1, 7, NA)))))))) %>%
  mutate(pid7_cat = ifelse(pid7 == 1, "Strong D", 
                           ifelse(pid7 == 2, "Weak D", 
                                  ifelse(pid7 == 3, "Lean D", 
                                         ifelse(pid7 == 4, "Independent", 
                                                ifelse(pid7 == 5, "Lean R", 
                                                       ifelse(pid7 == 6, "Weak R", 
                                                              ifelse(pid7 == 7, "Strong R", NA))))))))
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(pid3 = ifelse(pid7 == 1 | pid7 == 2 | pid7 == 3, 1, 
                       ifelse(pid7 == 4, 2, 
                              ifelse(pid7 == 5 | pid7 == 6 | pid7 == 7, 3, NA)))) %>%
  mutate(dem_dummy = ifelse(pid3 == 1, 1, NA)) %>%
  mutate(rep_dummy = ifelse(pid3 == 3, 1, NA))
Qualtrics2022$dem_dummy <- replace_na(Qualtrics2022$dem_dummy, 0)
Qualtrics2022$rep_dummy <- replace_na(Qualtrics2022$rep_dummy, 0)
Qualtrics2022$pid3 <- replace_na(Qualtrics2022$pid3, 2)
#
#
# SDO (Dominance)
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(SDO1 = ifelse(Qualtrics2022$Q364_1 == 1, 1, 
                       ifelse(Qualtrics2022$Q364_1 == 2, 2, 
                              ifelse(Qualtrics2022$Q364_1 == 3, 3, 
                                     ifelse(Qualtrics2022$Q364_1 == 4, 4, 
                                            ifelse(Qualtrics2022$Q364_1 == 5, 5, 
                                                   ifelse(Qualtrics2022$Q364_1 == 6, 6, 
                                                          ifelse(Qualtrics2022$Q364_1 == 7, 7, NA)))))))) %>%
  mutate(SDO1 = (SDO1 - 1)/6) %>%
  mutate(SDO2 = ifelse(Qualtrics2022$Q364_2 == 1, 7, 
                       ifelse(Qualtrics2022$Q364_2 == 2, 6, 
                              ifelse(Qualtrics2022$Q364_2 == 3, 5, 
                                     ifelse(Qualtrics2022$Q364_2 == 4, 4, 
                                            ifelse(Qualtrics2022$Q364_2 == 5, 3, 
                                                   ifelse(Qualtrics2022$Q364_2 == 6, 2, 
                                                          ifelse(Qualtrics2022$Q364_2 == 7, 1, NA)))))))) %>%
  mutate(SDO2 = (SDO2 - 1)/6) %>%
  mutate(SDO_domin = (SDO1 + SDO2)/2)
#
#
# SDO (Egalitarianism)
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(SDO3 = ifelse(Qualtrics2022$Q364_3 == 1, 1, 
                       ifelse(Qualtrics2022$Q364_3 == 2, 2, 
                              ifelse(Qualtrics2022$Q364_3 == 3, 3, 
                                     ifelse(Qualtrics2022$Q364_3 == 4, 4, 
                                            ifelse(Qualtrics2022$Q364_3 == 5, 5, 
                                                   ifelse(Qualtrics2022$Q364_3 == 6, 6, 
                                                          ifelse(Qualtrics2022$Q364_3 == 7, 7, NA)))))))) %>%
  mutate(SDO3 = (SDO3 - 1)/6) %>%
  mutate(SDO4 = ifelse(Qualtrics2022$Q364_4 == 1, 7, 
                       ifelse(Qualtrics2022$Q364_4 == 2, 6, 
                              ifelse(Qualtrics2022$Q364_4 == 3, 5, 
                                     ifelse(Qualtrics2022$Q364_4 == 4, 4, 
                                            ifelse(Qualtrics2022$Q364_4 == 5, 3, 
                                                   ifelse(Qualtrics2022$Q364_4 == 6, 2, 
                                                          ifelse(Qualtrics2022$Q364_4 == 7, 1, NA)))))))) %>%
  mutate(SDO4 = (SDO4 - 1)/6) %>%
  mutate(SDO_egal = (SDO3 + SDO4)/2)
#
#
# Household Income 
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(income_household1 = ifelse(income == 11, 6, 
                                    ifelse(income == 12, 7, 
                                           ifelse(income == 1 | income == 2, 1, 
                                                  ifelse(income == 3 | income == 4, 2, 
                                                         ifelse(income == 5 | income == 6, 3, 
                                                                ifelse(income == 7 | income == 8, 4, 
                                                                       ifelse(income == 9 | income == 10, 5, NA)))))))) %>%
  mutate(income_household = (income_household1 - 1)/6)
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(inc1 = ifelse(income_household1 == 1, 1, 0)) %>%
  mutate(inc2 = ifelse(income_household1 == 2, 1, 0)) %>%
  mutate(inc3 = ifelse(income_household1 == 3, 1, 0)) %>%
  mutate(inc4 = ifelse(income_household1 == 4, 1, 0)) %>%
  mutate(inc5 = ifelse(income_household1 == 5, 1, 0)) %>%
  mutate(inc6 = ifelse(income_household1 == 6, 1, 0)) %>%
  mutate(inc7 = ifelse(income_household1 == 7, 1, 0)) %>%
  mutate(inc_cat = ifelse(inc1 == 1, "lessthan20", 
                          ifelse(inc2 == 1, "20-39", 
                                 ifelse(inc3 == 1, "40-59", 
                                        ifelse(inc4 == 1, "60-79",
                                               ifelse(inc5 == 1, "80-99", 
                                                      ifelse(inc6 == 1, "100-150", 
                                                             ifelse(inc7 == 1, "150+", NA))))))))
#
#
# Ideology
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(ideology = ifelse(Q1...395 == 1, 1, 
                           ifelse(Q1...395 == 2, 2, 
                                  ifelse(Q1...395 == 3, 3, 
                                         ifelse(Q1...395 == 4, 4, 
                                                ifelse(Q1...395 == 5, 5, 
                                                       ifelse(Q1...395 == 6, 3, NA))))))) %>%
  mutate(ideology = (ideology - 1)/4)
#
#
# Authoritarianism
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(respect = ifelse(Qualtrics2022$auth1 == 2, 1, 
                          ifelse(Qualtrics2022$auth1 == 1, 0, NA))) %>%
  mutate(manners = ifelse(Qualtrics2022$auth3 == 2, 1, 
                          ifelse(Qualtrics2022$auth3 == 1, 0, NA))) %>%
  mutate(obedience = ifelse(Qualtrics2022$auth2 == 2, 0, 
                            ifelse(Qualtrics2022$auth2 == 1, 1, NA))) %>%
  mutate(behaved = ifelse(Qualtrics2022$auth5 == 2, 0, 
                          ifelse(Qualtrics2022$auth5 == 1, 1, NA))) %>% 
  mutate(auth_all = (respect + manners + obedience + behaved)/4)
#
#
# Blacks Feeling Thermometer
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(ft_blacks = thermoms_8/100)
#
#
# Whites Feeling Thermometer
Qualtrics2022 <- Qualtrics2022 %>% 
  mutate(ft_whites = thermoms_9/100)
#
#
# Trump Primary Voter
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(vote_trump_primary = ifelse(Qualtrics2022$Q375 == 1, 1, 0))
Qualtrics2022$vote_trump_primary <- replace_na(Qualtrics2022$vote_trump_primary, 0)
#
#
# Conspiratorial Thinking
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(vax_danger = ifelse(vax_danger == 1, 1, 
                             ifelse(vax_danger == 2, 0, NA))) %>%
  mutate(vax_work = ifelse(vax_work == 1, 1, 
                           ifelse(vax_work == 2, 0, NA)))
#
Qualtrics2022$vax_work <- replace_na(Qualtrics2022$vax_work, 0.5)
Qualtrics2022$vax_danger <- replace_na(Qualtrics2022$vax_danger, 0.5)
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(conspiratorial_thinking = (vax_danger + vax_work)/2)
#
#
# Religious Attendance
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(relig1 = (Q10 - 1)/5) %>%
  mutate(relig2 = (Q341 - 1)/5) 
#
Qualtrics2022$relig1 <- replace_na(Qualtrics2022$relig1, 0)
Qualtrics2022$relig2 <- replace_na(Qualtrics2022$relig2, 0)
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(relig_all = (relig1 + relig2))
#
#
#
#
#
# Confirmatory Factor Analysis (Table 1, Main Results) ----
#
cfa.model <- '
# Defining Variables
competitiveness =~ NA*fight + playtowin + fighters + ruthless

# Fixing variances
competitiveness ~~ 1*competitiveness
'
#
cfa.est <- cfa(cfa.model, Qualtrics2022, ordered = c("fight", "playtowin", "fighters", "ruthless"))
#
summary(cfa.est, standardized = T, fit.measures = T)
#
#
# Scale Validity
#
Qualtrics2022_comp <- data.frame(Qualtrics2022$fight, Qualtrics2022$playtowin, Qualtrics2022$fighters, Qualtrics2022$ruthless)
colnames(Qualtrics2022_comp) <- c("fight", "playtowin", "fighters", "ruthless")
#
validity <- omega(Qualtrics2022_comp, poly = T, nfactors = 1)
#
# Alpha
validity[["alpha"]]
#
# Omega
validity[["omega.tot"]]
#
#
#
#
#
# Creating weights ----
#
#
#
# Weight targets obtained from Supplementary Material Section 2.3 - "Weighted ANES (Republicans)"
#
# Just Republicans
#
Qualtrics2022_rep <- Qualtrics2022 %>%
  filter(pid3 == 3) %>%
  mutate(pid_strength = ifelse(pid7 == 5, "lean", 
                               ifelse(pid7 == 6, "weak", 
                                      ifelse(pid7 == 7, "strong", NA)))) %>%
  mutate(lean = ifelse(pid7 == 5, 1, 0)) %>%
  mutate(weak = ifelse(pid7 == 6, 1, 0)) %>%
  mutate(strong = ifelse(pid7 == 7, 1, 0))
Qualtrics2022_rep$pid_strength <- factor(Qualtrics2022_rep$pid_strength, levels = c("lean", "weak", "strong"))
#
Qualtrics2022_rep$race_cat <- factor(Qualtrics2022_rep$race_cat, levels = c("white", "black", "hispanic", "asian"))
Qualtrics2022_rep$edu_cat <- factor(Qualtrics2022_rep$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(female_cat = ifelse(gender == 2, "1", "0"))
#
targets <- list(
  female_cat = c("0" = 0.529, "1" = 0.471),
  race_cat = c("white" = 0.831, "black" = 0.022, "hispanic" = 0.082, "asian" = 0.025), 
  edu_cat = c("grad_school" = 0.104, "hs_or_less" = 0.356, "some_college" = 0.320, "college" = 0.219), 
  age_cat = c("18-24" = 0.081, "25-34" = 0.145, "35-44" = 0.168, 
              "45-54" = 0.184, "55-64" = 0.211, "65-74" = 0.140, "75+" = 0.071),
  inc_cat = c("lessthan20" = 0.066, "20-39" = 0.113, "40-59" = 0.125, 
              "60-79" = 0.140, "80-99" = 0.105, "100-150" = 0.230, "150+" = 0.219),
  pid_strength = c("lean" = 0.246, "weak" = 0.265, "strong" = 0.489)
)
Qualtrics2022_rep$female_cat <- factor(Qualtrics2022_rep$female_cat, 
                                levels = c("0", "1"))
Qualtrics2022_rep$race_cat <- factor(Qualtrics2022_rep$race_cat, 
                              levels = c("white", "black", "hispanic", "asian"))
Qualtrics2022_rep$edu_cat <- factor(Qualtrics2022_rep$edu_cat, 
                             levels = c("grad_school", "hs_or_less", "some_college", "college"))
Qualtrics2022_rep$age_cat <- factor(Qualtrics2022_rep$age_cat, 
                             levels = c("18-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75+"))
Qualtrics2022_rep$inc_cat <- factor(Qualtrics2022_rep$inc_cat, 
                             levels = c("lessthan20", "20-39", "40-59", "60-79", "80-99", "100-150", "150+"))
Qualtrics2022_rep$pid_strength <- factor(Qualtrics2022_rep$pid_strength, 
                                  levels = c("lean", "weak", "strong"))
#
Qualtrics2022_rep <- as.data.frame(Qualtrics2022_rep)
#
set.seed(1967)   
myweights_rep <- anesrake(targets, Qualtrics2022_rep, 
                          caseid = Qualtrics2022_rep$ResponseId, cap = 89, 
                          type = "pctlim", pctlim=.025, force1 = TRUE)
#
#
Qualtrics2022_rep$weight_full_rep <- unlist(myweights_rep[1])
#
#
#
#
# Creating Republican Qualtrics sample survey design object
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
#
#
#
#
# Main Results (Table 2, column 1, weighted) ----
#
#
#
table2_col1_w <- svyglm(jan6ok_prop ~ hypercompetitive + female + race_cat + age
                                 + income_household + edu_cat + relig_all, data = Qualtrics2022_rep, design = qualtrics_rep)
#
#
#
#
#
# Main Results (Table 2, column 2, unweighted panel data) ----
#
#
#
Qualtrics2020 <- read_sav("Qualtrics_2020.sav")
#
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(fight = ifelse(newcomp2 == 1, 1, 
                        ifelse(newcomp2 == 2, 0, NA))) %>%
  mutate(fighters = ifelse(newcomp4 == 1, 1, 
                           ifelse(newcomp4 == 2, 0, NA))) %>%
  mutate(ruthless = ifelse(newcomp8 == 1, 1, 
                           ifelse(newcomp8 == 2, 0, NA))) %>%
  mutate(playtowin = ifelse(newcomp11 == 1, 1, 
                            ifelse(newcomp11 == 2, 0, NA))) %>% 
  mutate(hypercompetitive_pre = (fight + playtowin + fighters + ruthless)/4)
#
#
merged_Qualtrics <- merge(Qualtrics2020, Qualtrics2022, by.x = 'PID.0', by.y = 'PID')
#
#
merged_Qualtrics2022_rep <- merged_Qualtrics %>%
  filter(pid3 == 3) %>%
  mutate(pid_strength = ifelse(pid7 == 5, "lean", 
                               ifelse(pid7 == 6, "weak", 
                                      ifelse(pid7 == 7, "strong", NA)))) %>%
  mutate(lean = ifelse(pid7 == 5, 1, 0)) %>%
  mutate(weak = ifelse(pid7 == 6, 1, 0)) %>%
  mutate(strong = ifelse(pid7 == 7, 1, 0))
merged_Qualtrics2022_rep$pid_strength <- factor(merged_Qualtrics2022_rep$pid_strength, levels = c("lean", "weak", "strong"))

merged_Qualtrics2022_rep$race_cat <- factor(merged_Qualtrics2022_rep$race_cat, levels = c("white", "black", "hispanic", "asian"))
merged_Qualtrics2022_rep$edu_cat <- factor(merged_Qualtrics2022_rep$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
#
#
table2_col2_unw <- lm(jan6ok_prop ~ hypercompetitive_pre + female + race_cat + age.y
                                     + income_household + edu_cat + relig_all, data = merged_Qualtrics2022_rep)
#
#
#
#
#
# Main Results (Table 3, weighted) ----
#
#
#
model_jan6_table3_w <- list()
#
# Column 1
model_jan6_table3_w[['I']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                       + income_household + edu_cat + relig_all + auth_all
                                       + conspiratorial_thinking, data = Qualtrics2022_rep, design=qualtrics_rep)
#
# Column 2
model_jan6_table3_w[['II']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                       + income_household + edu_cat + relig_all + auth_all
                                       + conspiratorial_thinking + vote_trump_primary + ideology 
                                       + SDO_domin + SDO_egal + ft_blacks + ft_whites, data = Qualtrics2022_rep, design = qualtrics_rep)
#
#
#
#
#
#
#
#
#
#
# Supplementary Material ----
#
#
#
#
#
# Section 2.1 ----
#
#
#
Qualtrics2022_desc_rep <- data.frame(Qualtrics2022_rep$hypercompetitive, Qualtrics2022_rep$jan6ok_prop, Qualtrics2022_rep$lean, Qualtrics2022_rep$weak, Qualtrics2022_rep$strong, 
                              Qualtrics2022_rep$auth_all, Qualtrics2022_rep$vote_trump_primary, Qualtrics2022_rep$conspiratorial_thinking, Qualtrics2022_rep$ideology, 
                              Qualtrics2022_rep$SDO_domin, Qualtrics2022_rep$SDO_egal, Qualtrics2022_rep$ft_blacks, Qualtrics2022_rep$ft_whites, 
                              Qualtrics2022_rep$relig_all, Qualtrics2022_rep$female, Qualtrics2022_rep$white, Qualtrics2022_rep$black, 
                              Qualtrics2022_rep$hispanic, Qualtrics2022_rep$asian, 
                              Qualtrics2022_rep$hs_or_less, Qualtrics2022_rep$some_college, Qualtrics2022_rep$college, Qualtrics2022_rep$grad_school, 
                              Qualtrics2022_rep$`18-24`, Qualtrics2022_rep$`25-34`, Qualtrics2022_rep$`35-44`, Qualtrics2022_rep$`45-54`, Qualtrics2022_rep$`55-64`, 
                              Qualtrics2022_rep$`65-74`, Qualtrics2022_rep$`75+`, Qualtrics2022_rep$inc1, Qualtrics2022_rep$inc2, 
                              Qualtrics2022_rep$inc3, Qualtrics2022_rep$inc4, Qualtrics2022_rep$inc5, Qualtrics2022_rep$inc6, Qualtrics2022_rep$inc7)
#
df_rep <- data.frame(unclass(summary(Qualtrics2022_desc_rep)), check.names = FALSE, stringsAsFactors = FALSE)
df_rep <- t(df_rep)
df_rep <- data.frame(df_rep)
df_rep <- df_rep %>%
  separate_wider_delim(X, delim = ":", names = c("X", "Minimum")) %>%
  separate_wider_delim(X.1, delim = ":", names = c("X1", "First_Quartile")) %>%
  separate_wider_delim(X.2, delim = ":", names = c("X2", "Median")) %>%
  separate_wider_delim(X.3, delim = ":", names = c("X3", "Mean")) %>%
  separate_wider_delim(X.4, delim = ":", names = c("X4", "Third_Quartile")) %>%
  separate_wider_delim(X.5, delim = ":", names = c("X5", "Maximum")) %>%
  separate_wider_delim(X.6, delim = ":", names = c("X6", "NAs")) %>% 
  mutate(Standard_Deviation = sapply(Qualtrics2022_desc_rep, sd, na.rm = TRUE)) %>%
  dplyr::select(Mean, Standard_Deviation, Minimum, First_Quartile, Median, Third_Quartile, Maximum)
#
df_rep <- data.frame(df_rep)
df_rep <- sapply(df_rep, as.numeric)
rownames(df_rep) <- c("Hypercompetitiveness", "Positivity toward January 6","Lean Republican", "Weak Republican", "Strong Republican",
                      "Authoritarian Submission", "Trump Primary Voter", "Conspiratorial Thinking", 
                      "Ideology", "SDO (Dominance)", "SDO (Egalitarianism)", "Blacks Feeling Thermometer", 
                      "Whites Feeling Thermometer", "Religious Attendance", "Female", 
                      "White", "Black", "Hispanic", "Asian", 
                      "High School or Less", "Some College", "College", "Graduate School", "18-24", "25-34", 
                      "35-44", "45-54", "55-64", "65-74", "75+", "Less than 19,999", "20,000 - 39,999", 
                      "40,000 - 59,999", "60,000 - 79,999", "80,000 - 99,999", "100,000 - 149,999", "More than 150,000")
#
#
#
#
#
# Section 2.2 ----
#
#
#
#
#
Qualtrics2022_desc <- data.frame(Qualtrics2022$hypercompetitive, Qualtrics2022$jan6ok_prop, 
                          Qualtrics2022$auth_all, Qualtrics2022$conspiratorial_thinking, Qualtrics2022$ideology, Qualtrics2022$SDO_domin,
                          Qualtrics2022$SDO_egal, Qualtrics2022$ft_blacks, Qualtrics2022$ft_whites, Qualtrics2022$relig_all, 
                          Qualtrics2022$female, Qualtrics2022$white, Qualtrics2022$black, Qualtrics2022$hispanic, Qualtrics2022$asian,
                          Qualtrics2022$hs_or_less, Qualtrics2022$some_college, 
                          Qualtrics2022$college, Qualtrics2022$grad_school, Qualtrics2022$dem_dummy, Qualtrics2022$rep_dummy, 
                          Qualtrics2022$`18-24`, Qualtrics2022$`25-34`, Qualtrics2022$`35-44`, Qualtrics2022$`45-54`, Qualtrics2022$`55-64`, 
                          Qualtrics2022$`65-74`, Qualtrics2022$`75+`, Qualtrics2022$inc1, Qualtrics2022$inc2, Qualtrics2022$inc3, Qualtrics2022$inc4,
                          Qualtrics2022$inc5, Qualtrics2022$inc6, Qualtrics2022$inc7)
#
df <- data.frame(unclass(summary(Qualtrics2022_desc)), check.names = FALSE, stringsAsFactors = FALSE)
df <- t(df)
df <- data.frame(df)
df <- df %>%
  separate_wider_delim(X, delim = ":", names = c("X", "Minimum")) %>%
  separate_wider_delim(X.1, delim = ":", names = c("X1", "First_Quartile")) %>%
  separate_wider_delim(X.2, delim = ":", names = c("X2", "Median")) %>%
  separate_wider_delim(X.3, delim = ":", names = c("X3", "Mean")) %>%
  separate_wider_delim(X.4, delim = ":", names = c("X4", "Third_Quartile")) %>%
  separate_wider_delim(X.5, delim = ":", names = c("X5", "Maximum")) %>%
  separate_wider_delim(X.6, delim = ":", names = c("X6", "NAs")) %>% 
  mutate(Standard_Deviation = sapply(Qualtrics2022_desc, sd, na.rm = TRUE)) %>%
  dplyr::select(Mean, Standard_Deviation, Minimum, First_Quartile, Median, Third_Quartile, Maximum)
#
df <- data.frame(df)
df <- sapply(df, as.numeric)
rownames(df) <- c("Hypercompetitiveness", "Positivity toward January 6", "Authoritarian Submission", 
                  "Conspiratorial Thinking", "Ideology", "SDO (Dominance)", "SDO (Egalitarianism)", 
                  "Blacks Feeling Thermometer", "Whites Feeling Thermometer", "Religious Attendance",
                  "Female", "White", "Black", "Hispanic", "Asian",
                  "High School or Less", "Some College", "College", "Graduate School", 
                  "Democrat Dummy", "Republican Dummy", "18-24", "25-34", "35-44", "45-54", "55-64", 
                  "65-74", "75+", "Less than 19,999", "20,000 - 39,999", "40,000 - 59,999", 
                  "60,000 - 79,999", "80,000 - 99,999", "100,000 - 149,999", "More than 150,000")
#
#
#
#
#
# Setting up ANES data for Sections 2.3 and 2.4 ----
#
anes2020_unweighted <- read.csv("anes_timeseries_2020_csv_20220210.csv")
#
# Age: V201507x
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201507x > 0) %>%
  mutate(age = V201507x)
#
# Age categories
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(age18_24 = ifelse(age >= 18 & age <= 24, 1, 0)) %>%
  mutate(age25_34 = ifelse(age >= 25 & age <= 34, 1, 0)) %>%
  mutate(age35_44 = ifelse(age >= 35 & age <= 44, 1, 0)) %>%
  mutate(age45_54 = ifelse(age >= 45 & age <= 54, 1, 0)) %>%
  mutate(age55_64 = ifelse(age >= 55 & age <= 64, 1, 0)) %>%
  mutate(age65_74 = ifelse(age >= 65 & age <= 74, 1, 0)) %>%
  mutate(age75_plus = ifelse(age >= 75, 1, 0))
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(age_factor = ifelse(age18_24 == 1, "18-24", 
                             ifelse(age25_34 == 1, "25-34", 
                                    ifelse(age35_44 == 1, "35-44", 
                                           ifelse(age45_54 == 1, "45-54", 
                                                  ifelse(age55_64 == 1, "55-65",
                                                         ifelse(age65_74 == 1, "65-74", 
                                                                ifelse(age75_plus == 1, "75+", NA))))))))
#
#
#
# Race: V201549x
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201549x > 0) %>%
  mutate(race = V201549x)
#
# Race categories
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(white_non_hisp = ifelse(race == 1, 1, 0)) %>%
  mutate(black_non_hisp = ifelse(race == 2, 1, 0)) %>%
  mutate(hispanic = ifelse(race == 3, 1, 0)) %>%
  mutate(asian_native_hawaii = ifelse(race == 4, 1, 0)) %>%
  mutate(other_multiple_race = ifelse(race == 5 | race == 6, 1, 0)) 
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(race_cat = ifelse(white_non_hisp == 1, "White", 
                           ifelse(black_non_hisp == 1, "Black", 
                                  ifelse(hispanic == 1, "Hispanic", 
                                         ifelse(asian_native_hawaii == 1, "Asian", 
                                                ifelse(other_multiple_race == 1, "Other/Multiple Races", NA))))))
#
#
# Gender: V201600
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201600 > 0) %>%
  mutate(sex = V201600)
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(male = ifelse(sex == 1, 1, 0)) %>%
  mutate(female = ifelse(sex == 2, 1, 0))
#
#
# Education: V201511x
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201511x > 0) %>%
  mutate(education = V201511x)
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(hs_or_less = ifelse(education == 1 | education == 2, 1, 0)) %>%
  mutate(some_college = ifelse(education == 3, 1, 0)) %>%
  mutate(bach = ifelse(education == 4, 1, 0)) %>%
  mutate(grad = ifelse(education == 5, 1, 0))
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(edu_cat = ifelse(hs_or_less == 1, "hs_or_less", 
                          ifelse(some_college == 1, "some_college", 
                                 ifelse(bach == 1, "college", 
                                        ifelse(grad == 1, "grad_school", NA)))))
#
#
# Household Income: V202468x
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V202468x > 0) %>%
  mutate(income = V202468x)
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(less_than_20 = ifelse(income == 1 | income == 2 | income == 3, 1, 0)) %>%
  mutate(twenty_to_40 = ifelse(income == 4 | income == 5 | income == 6 | income == 7, 1, 0)) %>%
  mutate(forty_to_60 = ifelse(income == 8 | income == 9 | income == 10, 1, 0)) %>%
  mutate(sixty_to_80 = ifelse(income == 11 | income == 12 | income == 13 | income == 14, 1, 0)) %>%
  mutate(eighty_to_100 = ifelse(income == 15 | income == 16, 1, 0)) %>%
  mutate(hundred_to_150 = ifelse(income == 17 | income == 18 |income == 19, 1, 0)) %>%
  mutate(onefif_above = ifelse(income == 20 | income == 21 |income == 22, 1, 0))
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(income_cat = ifelse(less_than_20 == 1, "lessthan20", 
                             ifelse(twenty_to_40 == 1, "20-39", 
                                    ifelse(forty_to_60 == 1, "40-59", 
                                           ifelse(sixty_to_80 == 1, "60-79", 
                                                  ifelse(eighty_to_100 == 1, "80-99", 
                                                         ifelse(hundred_to_150 == 1, "100-149", 
                                                                ifelse(onefif_above == 1, "150+", NA))))))))
#
#
# Ideology: V201200
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201200 > 0) %>%
  mutate(V201200 = ifelse(V201200 == 99, 4, V201200)) %>%
  mutate(ideology = V201200) %>%
  mutate(ideology_scaled = (ideology-1)/6)
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(extr_liberal = ifelse(ideology == 1, 1, 0)) %>%
  mutate(liberal = ifelse(ideology == 2, 1, 0)) %>%
  mutate(slight_liberal = ifelse(ideology == 3, 1, 0)) %>%
  mutate(moderate_nothing = ifelse(ideology == 4, 1, 0)) %>%
  mutate(slight_conservative = ifelse(ideology == 5, 1, 0)) %>%
  mutate(conservative = ifelse(ideology == 6, 1, 0)) %>%
  mutate(extr_conservative = ifelse(ideology == 7, 1, 0))
#
#
# PID (7pt): V201231x
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V201231x > 0) %>%
  mutate(pid7 = V201231x)
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(strong_D = ifelse(pid7 == 1, 1, 0)) %>%
  mutate(not_str_D = ifelse(pid7 == 2, 1, 0)) %>%
  mutate(lean_D = ifelse(pid7 == 3, 1, 0)) %>%
  mutate(independent = ifelse(pid7 == 4, 1, 0)) %>%
  mutate(lean_R = ifelse(pid7 == 5, 1, 0)) %>%
  mutate(not_str_R = ifelse(pid7 == 6, 1, 0)) %>%
  mutate(strong_R = ifelse(pid7 == 7, 1, 0))
#
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(pid7_cat = ifelse(strong_D == 1, "Strong D", 
                           ifelse(not_str_D == 1, "Weak D", 
                                  ifelse(lean_D == 1, "Lean D", 
                                         ifelse(independent == 1, "Independent", 
                                                ifelse(lean_R == 1, "Lean R", 
                                                       ifelse(not_str_R == 1, "Weak R", 
                                                              ifelse(strong_R == 1, "Strong R", NA))))))))
#
# PID (3pt)
anes2020_unweighted <- anes2020_unweighted %>%
  mutate(pid3 = ifelse(pid7 == 1 | pid7 == 2 | pid7 == 3, "Democrat", 
                       ifelse(pid7 == 5 | pid7 == 6 | pid7 == 7, "Republican", 
                              ifelse(pid7 == 4, "Independent", NA)))) %>%
  mutate(R_dummy = ifelse(pid3=="Republican", 1, 0)) %>%
  mutate(D_dummy = ifelse(pid3=="Democrat", 1, 0))
#
#
# Authority-mindedness: V202266, V202267, V202268, V202269
anes2020_unweighted <- anes2020_unweighted %>%
  filter(V202266 > 0) %>%
  mutate(auth_respect = ifelse(V202266 == 1, 0, 
                               ifelse(V202266 == 2, 1, 
                                      ifelse(V202266 == 3, 0.5, NA)))) %>%
  filter(V202267 > 0) %>%
  mutate(auth_manners = ifelse(V202267 == 1, 0, 
                               ifelse(V202267 == 2, 1, 
                                      ifelse(V202267 == 3, 0.5, NA)))) %>%
  filter(V202268 > 0) %>%
  mutate(auth_obed = ifelse(V202268 == 1, 1, 
                            ifelse(V202268 == 2, 0, 
                                   ifelse(V202268 == 3 | V202268 == 4, 0.5, NA)))) %>%
  filter(V202269 > 0) %>%
  mutate(auth_behaved = ifelse(V202269 == 1, 0, 
                               ifelse(V202269 == 2, 1, 
                                      ifelse(V202269 == 3, 0.5, NA)))) %>%
  mutate(auth_full = (auth_respect + auth_manners + auth_obed + auth_behaved)/4)
#
#
#
#
#
# Section 2.3: Unweighted ANES Means (Republicans) ----
#
anes2020_unw_repub <- anes2020_unweighted %>%
  filter(pid3 == "Republican")
#
vars_unw_rep <- data.frame(anes2020_unw_repub$age18_24, anes2020_unw_repub$age25_34, 
                           anes2020_unw_repub$age35_44, anes2020_unw_repub$age45_54, 
                           anes2020_unw_repub$age55_64, anes2020_unw_repub$age65_74, 
                           anes2020_unw_repub$age75_plus, anes2020_unw_repub$white_non_hisp, 
                           anes2020_unw_repub$black_non_hisp, anes2020_unw_repub$hispanic,
                           anes2020_unw_repub$asian_native_hawaii,
                           anes2020_unw_repub$female, anes2020_unw_repub$hs_or_less, 
                           anes2020_unw_repub$some_college, anes2020_unw_repub$bach, 
                           anes2020_unw_repub$grad, anes2020_unw_repub$less_than_20, 
                           anes2020_unw_repub$twenty_to_40, anes2020_unw_repub$forty_to_60, 
                           anes2020_unw_repub$sixty_to_80, anes2020_unw_repub$eighty_to_100, 
                           anes2020_unw_repub$hundred_to_150, anes2020_unw_repub$onefif_above, 
                           anes2020_unw_repub$auth_full, anes2020_unw_repub$strong_R, 
                           anes2020_unw_repub$not_str_R, anes2020_unw_repub$lean_R)
#
#
means <- sapply(vars_unw_rep, mean)
#
anes_means_unw_rep <- as.data.frame(means)
#
rownames(anes_means_unw_rep) <- sub("^anes2020_unw_repub.", "", rownames(anes_means_unw_rep))
#
#
#
#
#
# Section 2.3: Weighted ANES (Republicans) ----
#
anes_design_post <- 
  svydesign(
    ~V200010c,
    strata = ~V200010d,
    weights = ~V200010b, 
    nest = T, 
    data = anes2020_unweighted
  )
#
vars_w_rep <- data.frame("age18_24", "age25_34", "age35_44", "age45_54", 
                         "age55_64", "age65_74", "age75_plus", "white_non_hisp", 
                         "black_non_hisp", "hispanic", "asian_native_hawaii",
                         "female", "hs_or_less", "some_college", "bach", "grad", 
                         "less_than_20", "twenty_to_40", "forty_to_60", "sixty_to_80", 
                         "eighty_to_100", "hundred_to_150", "onefif_above", "auth_full", 
                         "strong_R", "not_str_R", "lean_R")
#
#
clean <- as.formula(paste("~", paste(vars_w_rep, collapse = " + ")))
#
#
anes_means_w_rep <- svyby(
  clean,
  ~R_dummy,
  design = anes_design_post,
  FUN = svymean,
  na.rm = TRUE,
  keep.var = TRUE
)
#
anes_means_w_rep <- t(anes_means_w_rep)
#
anes_means_w_rep <- anes_means_w_rep[rownames(anes_means_w_rep) %in% c("R_dummy", vars_w_rep), ]
#
anes_means_w_rep <- as.data.frame(anes_means_w_rep[, 2])
#
#
#
#
#
# Section 2.3: Unweighted Qualtrics Means (Republicans) ----
#
# Replicated from Supplementary Material "Section 2.2"
#
#
#
#
#
# Seciton 2.3: Weighted Qualtrics Means (Republicans) ----
#
# Using design object from "Creating Weights"
#
vars_w_rep2 <- c("18-24", "25-34", "35-44", "45-54",
                 "55-64", "65-74", "75+", "white", 
                 "black", "hispanic", "asian",
                 "female", "hs_or_less", "some_college", "college", "grad_school", 
                 "inc1", "inc2", "inc3", "inc4", 
                 "inc5", "inc6", "inc7", "auth_all", 
                 "strong", "weak", "lean", "hypercompetitive")
#
means_list <- lapply(vars_w_rep2, function(var) {
  fmla <- as.formula(paste0("~`", var, "`"))
  est <- svymean(fmla, design = qualtrics_rep, na.rm = TRUE)
  data.frame(Variable = var, Mean = coef(est))
})
#
qualtrics_means_w_rep <- do.call(rbind, means_list)
rownames(qualtrics_means_w_rep) <- NULL
#
#
#
#
#
# Section 2.4: Unweighted Qualtrics Means (Full) ----
#
# Replicated from Supplementary Material Section 2.2
#
#
#
#
#
# Section 2.4: Weighted ANES means (Full) ----
#
numeric_vars <- names(anes2020_unweighted)[sapply(anes2020_unweighted, is.numeric) & names(anes2020_unweighted) != "weights"]
#
# Compute weighted means
#
weighted_means <- sapply(numeric_vars, function(var) {
  mean_value <- svymean(as.formula(paste0("~", var)), anes_design_post)
  as.numeric(mean_value)
})

# Convert to data frame
#
weighted_means_df <- data.frame(variable = numeric_vars, weighted_mean = weighted_means)
anes_means_w <- weighted_means_df %>%
  filter(variable %in% c("auth_full", "ideology_scaled", "female", "white_non_hisp", "black_non_hisp", 
                         "hispanic", "asian_native_hawaii", "hs_or_less", "some_college", "bach", 
                         "grad", "age18_24", "age25_34", "age35_44", "age45_54", "age55_64", "age65_74", 
                         "age75_plus", "less_than_20", "twenty_to_40", "forty_to_60", "sixty_to_80", 
                         "eighty_to_100", "hundred_to_150", "onefif_above", "R_dummy", "D_dummy"))
#
#
#
#
#
# Section 3 ----
#
# Just Republicans, weighted
#
svyhist(~hypercompetitive, design = qualtrics_rep, breaks = c(-.125, .125, .375, .625, .875, 1.125), 
        axes = FALSE, freq = FALSE, xlab = c("Hypercompetitiveness"), main = "Republicans") 
axis(1, at=c(0, 0.25, 0.5, 0.75, 1))
axis(2, at=c(0, 0.5, 1.0, 1.5, 2))
#
#
#
#
#
# Creating weights for full Qualtrics Sample
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(female_cat = ifelse(female == 0, "0", 
                             ifelse(female == 1, "1", NA)))
#
targets <- list(
  female_cat = c("0" = 0.487, "1" = 0.513), 
  race_cat = c("white" = 0.699, "black" = 0.121, "hispanic" = 0.142, "asian" = 0.038), 
  edu_cat = c("grad_school" = 0.123, "hs_or_less" = 0.360, "some_college" = 0.290, "college" = 0.227), 
  age_cat = c("18-24" = 0.116, "25-34" = 0.171, "35-44" = 0.182, 
              "45-54" = 0.163, "55-64" = 0.179, "65-74" = 0.129, "75+" = 0.060),
  inc_cat = c("lessthan20" = 0.096, "20-39" = 0.134, "40-59" = 0.135, 
              "60-79" = 0.127, "80-99" = 0.095, "100-150" = 0.202, "150+" = 0.211),
  pid7_cat = c("Strong D" = 0.227, "Weak D" = 0.117, "Lean D" = 0.132, "Independent" = 0.132, 
               "Lean R" = 0.100, "Weak R" = 0.108, "Strong R" = 0.199) 
)
Qualtrics2022$female_cat <- factor(Qualtrics2022$female_cat, levels = c("0", "1"))
Qualtrics2022$race_cat <- factor(Qualtrics2022$race_cat, levels = c("white", "black", "hispanic", "asian"))
Qualtrics2022$edu_cat <- factor(Qualtrics2022$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
Qualtrics2022$age_cat <- factor(Qualtrics2022$age_cat, levels = c("18-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75+"))
Qualtrics2022$inc_cat <- factor(Qualtrics2022$inc_cat, levels = c("lessthan20", "20-39", "40-59", "60-79", "80-99", "100-150", "150+"))
Qualtrics2022$pid7_cat <- factor(Qualtrics2022$pid7_cat, levels = c("Strong D", "Weak D", "Lean D", "Independent", "Lean R", "Weak R", "Strong R"))
#
Qualtrics2022 <- as.data.frame(Qualtrics2022)
#
set.seed(1967) #Set the seed for replication  
myweights <- anesrake(targets, Qualtrics2022, 
                      caseid = Qualtrics2022$ResponseId, cap = 89, type = "pctlim", pctlim=.025, force1 = TRUE)
#
#
Qualtrics2022$weight_full <- unlist(myweights[1])
#
#
# Creating full Qualtrics survey design object
qualtrics_full <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full, 
    nest = T, 
    data = Qualtrics2022
  )
#
#
# All Respondents, weighted
#
svyhist(~hypercompetitive, design = qualtrics_full, breaks = c(-.125, .125, .375, .625, .875, 1.125), 
        axes = FALSE, freq = FALSE, , xlab = c("Hypercompetitiveness"), main = "All Respondents")
axis(1, at=c(0, 0.25, 0.5, 0.75, 1))
axis(2, at=c(0, 0.5, 1.0, 1.5, 2))
#
#
#
#
#
# Section 4 ----
#
#
#
model_hc_cov <- lm(hypercompetitive ~ dem_dummy + rep_dummy + female + white + black + hispanic + asian + age
                   + income_household + hs_or_less + some_college + college + ideology + SDO_domin + SDO_egal
                   + auth_all + relig_all + conspiratorial_thinking, data = Qualtrics2022)
#
#
#
#
#
# Section 5.1 ----
#
#
#
irt.table <- Qualtrics2022 %>%
  dplyr::select(fight, playtowin, fighters, ruthless)
#
irt <- ltm(irt.table ~ z1)
#
summary(irt)
#
#
#
#
#
# Section 5.2 ----
#
#
#
plot(irt, 
     lty = c(1, 2, 3, 4),
     col = "black",
     labels = c("", "", "", ""),
     xlab = "Hypercompetitiveness", 
     ylab = "Probability of a Hypercompetitive Response")
legend(x = 1.5, y=0.3,
       legend = c("Fight", "Play to Win", "Fighters", "Ruthless"),
       lty = c(1, 2, 3, 4),
       cex = 1)
#
#
#
#
#
# Section 5.3 ----
#
#
#
plot(irt,
     type = c("IIC"),
     items = c(0), 
     lty = 2, 
     xlim = c(-4, 4), 
     ylim = c(0, 4.5), 
     xlab = "Hypercompetitiveness", 
     ylab = "Information")

#
#
#
#
#
# Section 5.4 ----
#
#
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(fight20 = fight) %>%
  mutate(playtowin20 = playtowin) %>%
  mutate(fighters20 = fighters) %>%
  mutate(ruthless20 = ruthless)
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(fight22 = fight) %>%
  mutate(playtowin22 = playtowin) %>%
  mutate(fighters22 = fighters) %>%
  mutate(ruthless22 = ruthless)
#
merged_Qualtrics <- merge(Qualtrics2020, Qualtrics2022, by.x = 'PID.0', by.y = 'PID')
#
#
merged_Qualtrics2022_rep <- merged_Qualtrics %>%
  filter(pid3 == 3) %>%
  mutate(pid_strength = ifelse(pid7 == 5, "lean", 
                               ifelse(pid7 == 6, "weak", 
                                      ifelse(pid7 == 7, "strong", NA)))) %>%
  mutate(lean = ifelse(pid7 == 5, 1, 0)) %>%
  mutate(weak = ifelse(pid7 == 6, 1, 0)) %>%
  mutate(strong = ifelse(pid7 == 7, 1, 0))
merged_Qualtrics2022_rep$pid_strength <- factor(merged_Qualtrics2022_rep$pid_strength, levels = c("lean", "weak", "strong"))
#
merged_Qualtrics2022_rep$race_cat <- factor(merged_Qualtrics2022_rep$race_cat, levels = c("white", "black", "hispanic", "asian"))
merged_Qualtrics2022_rep$edu_cat <- factor(merged_Qualtrics2022_rep$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
#
VARS <- c("fight20", "playtowin20", "fighters20", "ruthless20",
          "fight22", "playtowin22", "fighters22", "ruthless22")
#
#
time.mod <- '
hc_pre =~ NA*fight20 + v1*fight20 + v2*playtowin20 + v3*fighters20 + v4*ruthless20
hc_post =~ NA*fight22 + v1*fight22 + v2*playtowin22 + v3*fighters22 + v4*ruthless22

hc_pre ~~ 1*hc_pre
hc_post ~~ 1*hc_post
fight20 ~~ fight22
playtowin20 ~~ playtowin22
fighters20 ~~ fighters22
ruthless20 ~~ ruthless22

fight20 | a1*t1
fight22 | a1*t1
playtowin20 | b1*t1
playtowin22 | b1*t1
fighters20 | c1*t1
fighters22 | c1*t1
ruthless20 | d1*t1
ruthless22 | d1*t1
'
#
#
fit.waves_rep <- cfa(time.mod, merged_Qualtrics2022_rep, mimic = "Mplus", ordered = VARS)
summary(fit.waves_rep, standardized = T)
#
fit.waves <- cfa(time.mod, merged_Qualtrics, mimic = "Mplus", ordered = VARS)
summary(fit.waves, standardized = T)
#
#
#
#
#
# Section 6.1 ----
#
#
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(fight = ifelse(newcomp2 == 1, 1, 
                        ifelse(newcomp2 == 2, 0, NA))) %>%
  mutate(forceful = ifelse(newcomp3 == 2, 1, 
                           ifelse(newcomp3 == 1, 0, NA))) %>%
  mutate(fighters = ifelse(newcomp4 == 1, 1, 
                           ifelse(newcomp4 == 2, 0, NA))) %>%
  mutate(weakness = ifelse(newcomp5 == 1, 1, 
                           ifelse(newcomp5 == 2, 0, NA))) %>%
  mutate(others = ifelse(newcomp6 == 1, 1, 
                         ifelse(newcomp6 == 2, 0, NA))) %>%
  mutate(unfair = ifelse(newcomp7 == 2, 1, 
                         ifelse(newcomp7 == 1, 0, NA))) %>%
  mutate(ruthless = ifelse(newcomp8 == 1, 1, 
                           ifelse(newcomp8 == 2, 0, NA))) %>%
  mutate(WhoWins = ifelse(newcomp9 == 1, 1, 
                          ifelse(newcomp9 == 4, 0, NA))) %>%
  mutate(playtowin = ifelse(newcomp11 == 1, 1, 
                            ifelse(newcomp11 == 2, 0, NA)))
#
#
#
cfa.model9 <- '
competitiveness =~ NA*fight + playtowin + fighters + ruthless + weakness + others + WhoWins + forceful + unfair

competitiveness ~~ 1*competitiveness
'
#
cfa.est9 <- cfa(cfa.model9, Qualtrics2020, ordered = c("fight", "playtowin", "fighters", "ruthless", "weakness", "others", "WhoWins", "forceful", "unfair"))
# 
summary(cfa.est9, standardized = T, fit.measures = T)
#
#
#
Qualtrics2020_comp <- data.frame(Qualtrics2020$fight, Qualtrics2020$playtowin, Qualtrics2020$fighters, Qualtrics2020$ruthless, 
                          Qualtrics2020$forceful, Qualtrics2020$weakness, Qualtrics2020$others, Qualtrics2020$unfair, Qualtrics2020$WhoWins)
colnames(Qualtrics2020_comp) <- c("fight", "playtowin", "fighters", "ruthless", 
                           "forceful", "weakness", "others", "unfair", "WhoWins")
#
validity <- omega(Qualtrics2020_comp, poly = T, nfactors = 1)
#
validity[["alpha"]]
#
validity[["omega.tot"]]
#
#
#
#
#
# Section 6.2 ----
#
#
#
irt.table <- Qualtrics2020 %>%
  dplyr::select(fight, playtowin, fighters, ruthless, 
                forceful, weakness, others, unfair, WhoWins)
#
irt <- ltm(irt.table ~ z1)
#
summary(irt)
#
#
#
#
# Section 7 ----
#
# Recoding Variables
#
# Authoritarianism
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(respect = ifelse(auth1 == 2, 1, 
                          ifelse(auth1 == 1, 0, NA))) %>%
  mutate(obey = ifelse(auth2 == 1, 1, 
                       ifelse(auth2 == 2, 0, NA))) %>%
  mutate(manners = ifelse(auth3 == 2, 1, 
                          ifelse(auth3 == 1, 0, NA))) %>%
  mutate(orderly = ifelse(auth4 == 1, 1, 
                          ifelse(auth4 == 2, 0, NA))) %>%
  mutate(auth_all = (respect + obey + manners + orderly)/4)
#
# Partisanship (7pt scale)
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(pid7 = ifelse(pid == 1 & dpid == 1, 1,
                       ifelse(pid == 1 & dpid == 2, 2, 
                              ifelse(pid == 3 & lean == 2, 3, 
                                     ifelse(pid == 3 & lean == 1, 5, 
                                            ifelse(pid == 2 & rpid == 2, 6, 
                                                   ifelse(pid == 2 & rpid == 1, 7, 
                                                          ifelse(pid == 3 & lean == 3, 4, NA)))))))) %>%
  mutate(pid7_scaled = (pid7 - 1)/6)
#
# Ideology
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(ideol_scaled = ifelse(ideology == 1, 1, 
                               ifelse(ideology == 2, 2, 
                                      ifelse(ideology == 3 | ideology == 6, 3, 
                                             ifelse(ideology == 4, 4, 
                                                    ifelse(ideology == 5, 5, NA)))))) %>%
  mutate(ideol_scaled = (ideol_scaled - 1)/4)
#
# Racial Resentment
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(resent1 = ifelse(rr_1 == 1, 1, 
                          ifelse(rr_1 == 2, 0.75, 
                                 ifelse(rr_1 == 3, 0.5, 
                                        ifelse(rr_1 == 4, 0.25, 
                                               ifelse(rr_1 == 5, 0, NA)))))) %>%
  mutate(resent2 = ifelse(rr_2 == 5, 1, 
                          ifelse(rr_2 == 4, 0.75, 
                                 ifelse(rr_2 == 3, 0.5, 
                                        ifelse(rr_2 == 2, 0.25, 
                                               ifelse(rr_2 == 1, 0, NA)))))) %>%
  mutate(resent3 = ifelse(rr_3 == 1, 1, 
                          ifelse(rr_3 == 2, 0.75, 
                                 ifelse(rr_3 == 3, 0.5, 
                                        ifelse(rr_3 == 4, 0.25, 
                                               ifelse(rr_3 == 5, 0, NA)))))) %>%
  mutate(resent4 = ifelse(rr_4 == 5, 1, 
                          ifelse(rr_4 == 4, 0.75, 
                                 ifelse(rr_4 == 3, 0.5, 
                                        ifelse(rr_4 == 2, 0.25, 
                                               ifelse(rr_4 == 1, 0, NA)))))) %>%
  mutate(racial_resent = (resent1 + resent2 + resent3 + resent4)/4)
#
# Female
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(female = ifelse(gender == 2, 1, 0))
#
# Race
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(black = ifelse(race == 2, 1, 0)) %>%
  mutate(hispanic = ifelse(race == 3, 1, 0)) %>%
  mutate(asian = ifelse(race == 4, 1, 0))
#
# Education
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(edu_cat = ifelse(edu == 1 | edu == 2, "hs_or_less", 
                          ifelse(edu == 3 | edu == 4, "some_college", 
                                 ifelse(edu == 5, "college", 
                                        ifelse(edu == 6 | edu == 7 | edu == 8, "grad_school", NA)))))
#
Qualtrics2020$edu_cat <- factor(Qualtrics2020$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
# Age
Qualtrics2020 <- Qualtrics2020 %>% 
  mutate(age_recoded = ifelse(age == 2, 1, 
                              ifelse(age == 3, 2, 
                                     ifelse(age == 4, 3, 
                                            ifelse(age == 5, 4, 
                                                   ifelse(age == 6, 5, 
                                                          ifelse(age == 7, 6, 
                                                                 ifelse(age == 8, 7, 
                                                                        ifelse(age == 9, 7, NA))))))))) %>%
  mutate(age = (age_recoded - 1)/6) 
#
# Income
#
Qualtrics2020 <- Qualtrics2020 %>% 
  mutate(income_household1 = ifelse(income == 11, 6, 
                                    ifelse(income == 12, 7, 
                                           ifelse(income == 1 | income == 2, 1, 
                                                  ifelse(income == 3 | income == 4, 2, 
                                                         ifelse(income == 5 | income == 6, 3, 
                                                                ifelse(income == 7 | income == 8, 4, 
                                                                       ifelse(income == 9 | income == 10, 5, NA)))))))) %>%
  mutate(income_household = (income_household1 - 1)/6)
#
# Immigration Policies
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(immig_typ = ifelse(Q247 == 1, 1, 
                            ifelse(Q247 == 2, 0.67, 
                                   ifelse(Q247 == 4, 0.33, 
                                          ifelse(Q247 == 5, 0, NA))))) %>%
  mutate(immig_dwit = ifelse(Q249 == 1, 1, 
                             ifelse(Q249 == 2, 0.67, 
                                    ifelse(Q249 == 3, 0.33, 
                                           ifelse(Q249 == 4, 0, NA)))))
#
# Capital Punishment Policies
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(capital_typ = ifelse(Q250 == 1, 1, 
                              ifelse(Q250 == 2, 0.67, 
                                     ifelse(Q250 == 3, 0.33, 
                                            ifelse(Q250 == 4, 0, NA))))) %>%
  mutate(capital_dwit = ifelse(Q251 == 1, 1, 
                               ifelse(Q251 == 2, 0.75, 
                                      ifelse(Q251 == 3, 0.5, 
                                             ifelse(Q251 == 4, 0.25, 
                                                    ifelse(Q251 == 5, 0, NA))))))
#
# Military Force Policies
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(milit_typ = ifelse(Q252 == 4, 1, 
                            ifelse(Q252 == 5, 0.75, 
                                   ifelse(Q252 == 7, 0.5, 
                                          ifelse(Q252 == 9, 0.25, 
                                                 ifelse(Q252 == 10, 0, NA)))))) %>%
  mutate(milit_dwit = ifelse(Q253 == 4, 1, 
                             ifelse(Q253 == 5, 0.75, 
                                    ifelse(Q253 == 7, 0.5, 
                                           ifelse(Q253 == 9, 0.25, 
                                                  ifelse(Q253 == 10, 0, NA))))))
#
#
#
#
#
# Table 7.1 ----
#
table7.1 <- list()
#
table7.1[['typical']] <- lm(immig_typ ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                              ideol_scaled + racial_resent + female + black + hispanic + asian + 
                              edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.1[['typical']])
#
table7.1[['whatever it takes']] <- lm(immig_dwit ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                              ideol_scaled + racial_resent + female + black + hispanic + asian + 
                              edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.1[['whatever it takes']])
#
#
#
#
#
# Table 7.2 ----
#
table7.2 <- list()
#
table7.2[['typical']] <- lm(capital_typ ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                              ideol_scaled + racial_resent + female + black + hispanic + asian + 
                              edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.2[['typical']])
#
table7.2[['whatever it takes']] <- lm(capital_dwit ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                                        ideol_scaled + racial_resent + female + black + hispanic + asian + 
                                        edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.2[['whatever it takes']])
#
#
#
#
#
# Table 7.3 ----
#
table7.3 <- list()
#
table7.3[['typical']] <- lm(milit_typ ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                              ideol_scaled + racial_resent + female + black + hispanic + asian + 
                              edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.3[['typical']])
#
table7.3[['whatever it takes']] <- lm(milit_dwit ~ hypercompetitive_pre + auth_all + pid7_scaled + 
                                        ideol_scaled + racial_resent + female + black + hispanic + asian + 
                                        edu_cat + age + income_household1, data = Qualtrics2020)
summary(table7.3[['whatever it takes']])
#
#
#
#
#
# Table 7.4 ----
#
Qualtrics2020 <- Qualtrics2020 %>%
  mutate(sports_fan = ifelse(Q318 == 1, 1, 
                             ifelse(Q318 == 2, 0, NA))) %>%
  mutate(patriots_ft = thermom_anes_8) %>%
  mutate(astros_ft = thermom_anes_16)
#
Qualtrics2020_sports_fan <- Qualtrics2020 %>%
  dplyr::filter(sports_fan == 1)
#
aggregate(cbind(patriots_ft, astros_ft) ~ hypercompetitive_pre, data = Qualtrics2020_sports_fan, FUN = mean)
#
#
#
Qualtrics2021 <- read.csv("Qualtrics_2021.csv")
#
Qualtrics2021 <- Qualtrics2021 %>%
  mutate(fight = ifelse(newcomp2 == "Only those who fight for their way are successful", 1, 
                        ifelse(newcomp2 == "Cooperation is the key to success", 0, NA))) %>%
  mutate(fighters = ifelse(newcomp4 == "Only fighters make it in this world", 1, 
                           ifelse(newcomp4 == "Understanding others allows people to make it in this world", 0, NA))) %>%
  mutate(ruthless = ifelse(newcomp8 == "People must be ruthless at times", 1, 
                           ifelse(newcomp8 == "People can always find ways to cooperate", 0, NA))) %>%
  mutate(playtowin = ifelse(newcomp11 == "In sports and life, you should always \"play to win\"", 1, 
                            ifelse(newcomp11 == "In sports and life, it's not whether you win or lose, but \"how you play the game\"", 0, NA))) %>%
  mutate(hypercompetitive = (fight + fighters + ruthless + playtowin)/4)
#
Qualtrics2021 <- Qualtrics2021 %>%
  mutate(sports_fan1 = ifelse(sports_fan == "Yes", 1, 0)) %>%
  mutate(packers_ft = as.numeric(thermoms2_8)) %>%
  mutate(dodgers_ft = as.numeric(thermoms2_9))
#
Qualtrics2021_sports_fan <- Qualtrics2021 %>%
  dplyr::filter(sports_fan1 == 1)
#
aggregate(cbind(packers_ft, dodgers_ft) ~ hypercompetitive, data = Qualtrics2021_sports_fan, FUN = mean, na.rm = TRUE)
#
#
#
Qualtrics2020_sports_fan$sport_FT <- (Qualtrics2020_sports_fan$patriots_ft + Qualtrics2020_sports_fan$astros_ft)/200
Qualtrics2021_sports_fan$sport_FT <- (Qualtrics2021_sports_fan$packers_ft + Qualtrics2021_sports_fan$dodgers_ft)/200
#
sports2020 <- lm(hypercompetitive_pre ~ sport_FT, data = Qualtrics2020_sports_fan)
sports2021 <- lm(hypercompetitive ~ sport_FT, data = Qualtrics2021_sports_fan)
#
#
#
#
#
# Section 8 ----
#
#
#
no_models <- list()
#
no_models[['All 5 Pairs']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                     + income_household + edu_cat + relig_all + auth_all
                                     + vote_trump_primary + conspiratorial_thinking + ideology 
                                     + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                     data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['All 5 Pairs']])
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(jan6_pos_no_acc = patriotic + justified + legitdiscourse + unplanned) %>%
  mutate(jan6_neg_no_acc = unpatriotic + unjustified + violent + planned) %>%
  mutate(jan6ok_prop_no_acc = jan6_pos_no_acc/(jan6_pos_no_acc + jan6_neg_no_acc))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
no_models[['No Acc/Unacc']] <- svyglm(jan6ok_prop_no_acc ~ hypercompetitive + pid_strength + female + race_cat + age
                                      + income_household + edu_cat + relig_all + auth_all
                                      + vote_trump_primary + conspiratorial_thinking + ideology 
                                      + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                      data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['No Acc/Unacc']])
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(jan6_pos_no_pat = acceptable + justified + legitdiscourse + unplanned) %>%
  mutate(jan6_neg_no_pat = unacceptable + unjustified + violent + planned) %>%
  mutate(jan6ok_prop_no_pat = jan6_pos_no_pat/(jan6_pos_no_pat + jan6_neg_no_pat))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
no_models[['No Pat/Unpat']] <- svyglm(jan6ok_prop_no_pat ~ hypercompetitive + pid_strength + female + race_cat + age
                                      + income_household + edu_cat + relig_all + auth_all
                                      + vote_trump_primary + conspiratorial_thinking + ideology 
                                      + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                      data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['No Pat/Unpat']])
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(jan6_pos_no_just = acceptable + patriotic + legitdiscourse + unplanned) %>%
  mutate(jan6_neg_no_just = unacceptable + unpatriotic + violent + planned) %>%
  mutate(jan6ok_prop_no_just = jan6_pos_no_just/(jan6_pos_no_just + jan6_neg_no_just))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
no_models[['No Just/Unjust']] <- svyglm(jan6ok_prop_no_just ~ hypercompetitive + pid_strength + female + race_cat + age
                                        + income_household + edu_cat + relig_all + auth_all
                                        + vote_trump_primary + conspiratorial_thinking + ideology 
                                        + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                        data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['No Just/Unjust']])
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(jan6_pos_no_ldsc = acceptable + patriotic + justified + unplanned) %>%
  mutate(jan6_neg_no_ldsc = unacceptable + unpatriotic + unjustified + planned) %>%
  mutate(jan6ok_prop_no_ldsc = jan6_pos_no_ldsc/(jan6_pos_no_ldsc + jan6_neg_no_ldsc))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
no_models[['No LDsc/Viol']] <- svyglm(jan6ok_prop_no_ldsc ~ hypercompetitive + pid_strength + female + race_cat + age
                                      + income_household + edu_cat + relig_all + auth_all
                                      + vote_trump_primary + conspiratorial_thinking + ideology 
                                      + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                      data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['No LDsc/Viol']])
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(jan6_pos_no_unpl = acceptable + patriotic + justified + legitdiscourse) %>%
  mutate(jan6_neg_no_unpl = unacceptable + unpatriotic + unjustified + violent) %>%
  mutate(jan6ok_prop_no_unpl = jan6_pos_no_unpl/(jan6_pos_no_unpl + jan6_neg_no_unpl))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
no_models[['No Unpl/Plan']] <- svyglm(jan6ok_prop_no_unpl ~ hypercompetitive + pid_strength + female + race_cat + age
                                      + income_household + edu_cat + relig_all + auth_all
                                      + vote_trump_primary + conspiratorial_thinking + ideology 
                                      + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                      data = Qualtrics2022_rep, design = qualtrics_rep)
summary(no_models[['No Unpl/Plan']])
#
#
#
#
#
# Section 9 ----
#
#
#
model_jan6_table3_w <- list()
#
# Column 1
model_jan6_table3_w[['I']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                     + income_household + edu_cat + relig_all + auth_all
                                     + conspiratorial_thinking, data = Qualtrics2022_rep, design=qualtrics_rep)
#
# Column 2
model_jan6_table3_w[['II']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                      + income_household + edu_cat + relig_all + auth_all
                                      + conspiratorial_thinking + vote_trump_primary + ideology 
                                      + SDO_domin + SDO_egal + ft_blacks + ft_whites, data = Qualtrics2022_rep, design = qualtrics_rep)
#
#
#
#
#
# Section 10 ----
#
#
#
Qualtrics2022 <- Qualtrics2022 %>%
  mutate(ft_trump = thermoms_1/100)
#
Qualtrics2022_ind_dem <- Qualtrics2022 %>%
  filter(pid3 == 1 | pid3 == 2) %>%
  mutate(ft_trump = thermoms_1/100)
#
Qualtrics2022_ind_dem$race_cat <- factor(Qualtrics2022_ind_dem$race_cat, levels = c("white", "black", "hispanic", "asian"))
Qualtrics2022_ind_dem$edu_cat <- factor(Qualtrics2022_ind_dem$edu_cat, levels = c("grad_school", "hs_or_less", "some_college", "college"))
#
#
model_jan6_interaction <- lm(jan6ok_prop ~ hypercompetitive*ft_trump + dem_dummy + female + race_cat
                             + age + income_household + edu_cat + relig_all + auth_all + conspiratorial_thinking 
                             + ideology + SDO_domin + SDO_egal + ft_blacks + ft_whites, data = Qualtrics2022_ind_dem)
#
#
#
#
#
# Section 11 ----
#
#
#
# Table 2, Col. 1 (Weighted)
#
Qualtrics2022_rep_scaled <- Qualtrics2022_rep %>%
  mutate(across(where(is.numeric) & !all_of("weight_full_rep"), scale))
#
qualtrics_rep_scaled <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep_scaled
  )
#
# 
table2_stand <- list()
#
table2_stand[['Table 2, Col. 1 (W)']] <- svyglm(jan6ok_prop ~ hypercompetitive + female + race_cat + age
                                                + income_household + edu_cat + relig_all, 
                                                data = Qualtrics2022_rep_scaled, design = qualtrics_rep_scaled)
#
#
# Table 2, Col. 2 (Unweighted)
#
merged_Qualtrics2022_rep_scaled <- merged_Qualtrics2022_rep %>%
  mutate(across(where(is.numeric), scale))
#
table2_stand[['Table 2, Col. 2 (Unw.)']] <- lm(jan6ok_prop ~ hypercompetitive_pre + female + race_cat + age.y
                                               + income_household + edu_cat + relig_all, data = merged_Qualtrics2022_rep_scaled)
#
#
#
# Main Results (Table 3, weighted)
#
table3_stand <- list()
#
# Column 1
#
table3_stand[['Table 3, Col. 1 (W)']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                                + income_household + edu_cat + relig_all + auth_all
                                                + conspiratorial_thinking, 
                                                data = Qualtrics2022_rep_scaled, design=qualtrics_rep_scaled)
#
# Column 2
#
table3_stand[['Table 3, Col. 2 (W)']] <- svyglm(jan6ok_prop ~ hypercompetitive + pid_strength + female + race_cat + age
                                                + income_household + edu_cat + relig_all + auth_all
                                                + conspiratorial_thinking + vote_trump_primary + ideology 
                                                + SDO_domin + SDO_egal + ft_blacks + ft_whites, 
                                                data = Qualtrics2022_rep_scaled, design = qualtrics_rep_scaled)
#
#
#
#
# 
# Section 12.1 ----
#
#
#
Qualtrics2022_rep <- Qualtrics2022 %>%
  filter(pid3 == 3)
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(ft_trump_recoded = ifelse(ft_trump >= 0 & ft_trump <= .49, 0, 
                                   ifelse(ft_trump >= .50 & ft_trump <= .79, 0.5, 
                                          ifelse(ft_trump >= .80 & ft_trump <= 1, 1, NA))))
#
Qualtrics2022_rep$weight_full_rep <- unlist(myweights_rep[1])
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
#
model_ft_trump_recoded <- svyglm(jan6ok_prop ~ hypercompetitive*ft_trump_recoded, 
                                 data = Qualtrics2022_rep, design = qualtrics_rep)
#
#
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(HC_3cat = ifelse(hypercompetitive == 0, "0", 
                          ifelse(hypercompetitive == 0.25 | hypercompetitive == 0.5, "1-2", 
                                 ifelse(hypercompetitive == 0.75 | hypercompetitive == 1, "3-4", NA))))
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(ft_trump_recoded = ifelse(ft_trump <= 0.70, "0-70", 
                                      ifelse(ft_trump >0.70 & ft_trump <= .95, "71-95", 
                                             ifelse(ft_trump >.95, "96-100", NA))))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
#
svyby(~jan6ok_prop, 
      by = ~ft_trump_recoded + HC_3cat, 
      FUN = svymean, na.rm=T, 
      design = qualtrics_rep)
#
#
t(table(qualtrics_rep$variables$ft_trump_recoded,
  qualtrics_rep$variables$HC_3cat,
  useNA = "no"
))
#
#
#
#
#
# Section 12.2 ----
#
#
#
Qualtrics2022_rep <- Qualtrics2022_rep %>%
  mutate(strong = ifelse(pid7_cat == "Strong R", 1, 0))
#
qualtrics_rep <- 
  svydesign(
    ids = ~1,
    weights = ~weight_full_rep, 
    nest = T, 
    data = Qualtrics2022_rep
  )
#
#
model_HC_strong_R <- svyglm(jan6ok_prop ~ hypercompetitive*strong, 
                            data = Qualtrics2022_rep, design = qualtrics_rep)
#
#
#
#
#
#
#
#
#
#
#
#